package com.example.emos.wx.user.shiro;

import org.springframework.stereotype.Component;

/**
 * 传递Token信息的媒介类：ThreadLocalToken
 * 使用ThreadLocal技术实现
 *
 * @Author YinXi
 * @Versin 1.0.0
 * @Date 2023/7/28
 */
@Component
public class ThreadLocalToken {
    /**
     * 定义ThreadLocal
     */
    private ThreadLocal<String> local = new ThreadLocal<>();

    /**
     * 将token放到ThreadLocal
     *
     * @param token token字符串
     */
    public void setToken(String token) {
        local.set(token);
    }

    /**
     * 从ThreadLocal获取Token
     *
     * @return Token字符串
     */
    public String getToken() {
        return local.get();
    }

    /**
     * 从ThreadLocal移除Token
     */
    public void clear() {
        local.remove();
    }
}
